package com.langfeiyes.pattern.iterator;

public class ConcreteIterator<E> implements Iterator<E>{
    private int index = -1; //索引
    private ConcreteAggregate concreteAggregate;
    public ConcreteIterator(ConcreteAggregate concreteAggregate) {
        this.concreteAggregate = concreteAggregate;
    }
    @Override
    public E next() {
        if(index < concreteAggregate.size()){
            index = index + 1;
        }
        return (E) concreteAggregate.get(index);
    }
    @Override
    public boolean hasNext() {
        return index < concreteAggregate.size()-1;
    }
}
